package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.OrderItem;
import com.example.service.OrderItemService;
import com.example.mapper.OrderItemMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author circle48
* @description 针对表【order_item(订单项信息)】的数据库操作Service实现
* @createDate 2024-05-14 11:46:02
*/
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem>
    implements OrderItemService{
    @Override
    public List<OrderItem> selectList(LambdaQueryWrapper<OrderItem> queryWrapper) {
        return baseMapper.selectList(queryWrapper);
    }


    @Override
    public List<OrderItem> getByOrderId(Long orderId) {
        // 使用 LambdaQueryWrapper 创建查询条件
        LambdaQueryWrapper<OrderItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderItem::getOrderId, orderId);
        // 调用 baseMapper 的 selectList 方法执行查询
        return baseMapper.selectList(queryWrapper);
    }


    @Override
    public OrderItem getByOrderAndSkuId(Long orderId, Long skuId) {
        return baseMapper.selectOne(
                new LambdaQueryWrapper<OrderItem>()
                        .eq(OrderItem::getOrderId, orderId)
                        .eq(OrderItem::getSkuId, skuId)
        );
    }
}